#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2010;

class BinaryIndexedTree
{
private:
    vector<int> tree;

public:
    BinaryIndexedTree(int n) : tree(n + 1) {}

    void add(int i)
    {
        while (i < tree.size())
        {
            tree[i] += 1;
            i += i & -i;
        }
    }

    int get(int i)
    {
        int res = 0;
        while (i > 0)
        {
            res += tree[i];
            i &= i - 1;
        }
        return res;
    }
};

typedef unsigned long long ull;
ull BASE = 233;
struct HashSeq{
    vector<ull> P, H;

    HashSeq(string& s){
        int n = s.size();
        P.resize(n + 1);
        P[0] = 1;
        for(int i = 1; i <= n; i++) P[i] = P[i - 1] * BASE;
        H.resize(n + 1);
        H[0] = 0;
        for(int i = 1; i <= n; i++)H[i] = H[i - 1] * BASE + s[i - 1]; 
    }

    ull query(int l, int r){
        return H[r] - H[l - 1] * P[r - l + 1];
    }
};

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qui(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % MOD;
        b >>= 1;
        a = a * a % MOD;
    }
    return res;
}

ll fac[N], inv_fac[N];
ll S[N][N];

void init()
{
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = fac[i - 1] * i % MOD;
    inv_fac[N - 1] = qui(fac[N - 1], MOD - 2);
    for (int i = N - 1; i > 0; i--)
        inv_fac[i - 1] = inv_fac[i] * i % MOD;
    S[0][0] = 1;
    for (int i = 1; i < N; ++i)
    {
        for (int j = 1; j < N; ++j)
        {
            S[i][j] = (j * S[i - 1][j] % MOD + S[i - 1][j - 1]) % MOD;
        }
    }
}

ll comb(int a, int b)
{
    return fac[a] * inv_fac[b] % MOD * inv_fac[a - b] % MOD;
}

// 第一类斯特林数
ll s[N][N];
void sinit()
{
    s[0][0] = 1;
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= i; ++j)
        {
            s[i][j] = (s[i - 1][j - 1] + (i - 1) * s[i - 1][j]) % MOD;
        }
    }
}

// 质数筛
const int PRIME_N = 100000;
bool st[PRIME_N];
int primes[PRIME_N];
int cnt;
void fun()
{
    st[1] = true;
    for (int i = 2; i < PRIME_N; i++)
    {
        if (!st[i])
        {
            primes[cnt++] = i;
        }
        for (int j = 0; i * primes[j] < PRIME_N; j++)
        {
            st[i * primes[j]] = true;
            if (i % primes[j] == 0)
                break;
        }
    }
}

bool check(auto& a) {
    int t = gcd(a[0], a[1]);
    for(int i = 1; i < a.size() - 1; i++) {
        int b = gcd(a[i], a[i + 1]);
        if(b < t){
            return false;
        }
        t = b;
    }
    return true;
}

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int g = -1;
    int t = gcd(a[0], a[1]);
    for(int i = 1; i < n - 1; i++) {
        int b = gcd(a[i], a[i + 1]);
        if(b < t){
            g = i;
            break;
        }
        t = b;
    }
    if(g == -1) {
        cout << "YES\n";
        return;
    }
    for(int i = g - 1; i <= g + 1; i++) {
        vector<int> t;
        if(i >= 0 && i < n) {
            for(int j = 0; j < n; j++) {
                if(i == j) continue;
                t.push_back(a[j]);
            }
            if(check(t)){
                cout << "YES\n";
                return;
            }
        }
    }
    cout << "NO\n";
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}